package com.strelitzia.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.strelitzia.admin.Entity.UserEntity;
import com.strelitzia.admin.constant.AdminConstant;
import com.strelitzia.admin.service.DynamicService;
import com.strelitzia.admin.service.PhotoService;
import com.strelitzia.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


import javax.servlet.http.HttpSession;


/**
 * @create 2024/1/21 10:46
 */
@Controller
public class PageController {
    @Autowired
    UserService userService;
    @Autowired
    DynamicService dynamicService;
    @Autowired
    PhotoService photoService;

    @GetMapping("/")
    public String page(HttpSession session) {
        Object attribute = session.getAttribute(AdminConstant.SessionId);
        if (attribute != null) {
            return "redirect:/index";
        }
        return "login";
    }




    @GetMapping("/index")
    public String index(Model model) {
        int count = userService.count();
        int count1 = dynamicService.count();
        int count2 = photoService.count();
        int count3 = userService.count(new QueryWrapper<UserEntity>().eq("status", 1));
        model.addAttribute("account", count);
        model.addAttribute("account_online", count3);
        model.addAttribute("dynamic", count1);
        model.addAttribute("photo", count2);
        return "index";
    }


}
